package br.com.serctam.session;

import java.util.ArrayList;
import java.util.List;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.framework.EntityQuery;

import br.com.serctam.entity.Cargo;
import br.com.serctam.entity.Concurso;

@Scope(ScopeType.CONVERSATION)
@Name("cargoList")
public class CargoList extends EntityQuery<Cargo>
{
	
	
	public Concurso concurso;
	
	
    public Concurso getConcurso() {
		return concurso;
	}


	public void setConcurso(Concurso concurso) {
		this.concurso = concurso;
	}


	public CargoList()
    {
        setEjbql(" select cargo from Cargo cargo order by cargo.concurso.nome , cargo.codigo ");
    }
    
    
	@Out(value="listaDeCargos", required=false)
	List<Cargo> cargoList = null;
	
    public List<Cargo> getCargoList() {
		return cargoList;
	}
	public void setCargoList(List<Cargo> cargoList) {
		this.cargoList = cargoList;
	}

	@Begin(join=true)
	public List<Cargo> buscar(){
    	
    	//List<Cargo> list = null;
    	if (concurso == null){
    		cargoList = new ArrayList<Cargo>(0);
    		return cargoList;
    	}
    	setEjbql(" select cargo from Cargo cargo inner join cargo.concurso concurso where concurso.id = " + concurso.getId() + " order by cargo.concurso.nome , cargo.codigo ");
    	cargoList = getResultList();
    	return getResultList();
    	
    }
}
